//
//  YHHoemAgentSubCell.m
//  YHApp
//
//  Created by -- on 2021/7/12.
//

#import "HAHoemAgentSubCell.h"
#import "HAHoemAgentListModel.h"

@interface HAHoemAgentSubCell ()

/***/
@property (nonatomic, strong) UIView *mainV;
/***/
@property (nonatomic, strong) UIImageView *iconImgV;
/***/
@property (nonatomic, strong) UILabel *nameL;
/***/
@property (nonatomic, strong) UILabel *mobileL;
/***/
@property (nonatomic, strong) UILabel *timeL;
/***/
@property (nonatomic, strong) UIImageView *rImgV;
/***/
@property (nonatomic, strong) UILabel *yjL;
/***/
@property (nonatomic, strong) UIView *lineV;
/***/
@property (nonatomic, strong) UIButton *bottomBtn1;
/***/
@property (nonatomic, strong) UIButton *bottomBtn2;

@end

@implementation HAHoemAgentSubCell

-(void)bottomBtn1Click {
    if (self.YHHoemAgentSubCellBt1CBlock) {
        self.YHHoemAgentSubCellBt1CBlock(_model);
    }
}

-(void)bottomBtn2Click {
    if (self.YHHoemAgentSubCellBt2CBlock) {
        self.YHHoemAgentSubCellBt2CBlock(_model);
    }
}

-(void)iconImgVClick {
    if (self.isCanPhone) {
        [HAHelper toPhone:self.model.mobile];
    }
}

-(void)setModel:(HAHoemAgentListModel *)model {
    _model = model;
    
    [self.iconImgV setImageWithURL:[NSURL URLWithString:_model.avatar] placeholder:nil];
    
    NSString *name = _model.name;
    NSString *grades_name = _model.grades_name;
    if (![NSString isEmptyString:grades_name] && ![NSString isEmptyString:grades_name]) {
        NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@ %@",name,grades_name]];
        [attr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:[[attr string]rangeOfString:grades_name]];
        [attr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#5F67FC"] range:[[attr string]rangeOfString:grades_name]];
        self.nameL.attributedText = attr;
    }else {
        self.nameL.text = name;
    }
    
    self.mobileL.text = model.mobileview;
    self.timeL.text = [NSString stringWithFormat:@"加入时间%@",[NSString timeStampToString:_model.jointime Formatter:@"yyyy-MM-dd HH:mm"]];
}

-(void)layoutSubviews {
    [super layoutSubviews];
    
    self.contentView.backgroundColor = [UIColor khaBGColor];
    
    [self.mainV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(-10);
        make.top.mas_equalTo(0);
    }];
    
    [self.lineV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.bottom.mas_equalTo(-54);
        make.height.mas_offset(1);
    }];
    
    [self.iconImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(11);
        make.width.mas_offset(45);
        make.height.mas_offset(45);
    }];
    
    [self.rImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_offset(5);
        make.height.mas_offset(10);
        make.centerY.mas_equalTo(self.iconImgV);
        make.right.mas_equalTo(-20);
    }];
    
    [self.yjL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_offset(36);
        make.centerY.mas_equalTo(self.iconImgV);
        make.right.mas_equalTo(self.rImgV.mas_left).offset(-8);
    }];
    
    [self.nameL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.iconImgV.mas_right).offset(15);
        make.right.mas_equalTo(self.yjL.mas_left).offset(-5);
        make.centerY.mas_equalTo(self.iconImgV).offset(-12);
    }];
    
    [self.mobileL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.nameL);
        make.right.mas_equalTo(self.nameL);
        make.top.mas_equalTo(self.nameL.mas_bottom).offset(6);
    }];
    
    [self.timeL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.nameL);
        make.right.mas_equalTo(self.nameL);
        make.top.mas_equalTo(self.mobileL.mas_bottom).offset(6);
    }];

    [self.bottomBtn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-20);
        make.bottom.mas_equalTo(-13);
        make.width.mas_offset(78);
        make.height.mas_offset(28);
    }];
    [self.bottomBtn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.bottomBtn1.mas_left).offset(-8);
        make.bottom.mas_equalTo(-13);
        make.width.mas_offset(78);
        make.height.mas_offset(28);
    }];

}

- (UIView *)mainV
{
    if (!_mainV) {
        _mainV = [UIView ha_createView];
        _mainV.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_mainV];
    }
    return _mainV;
}
- (UIImageView *)iconImgV
{
    if (!_iconImgV) {
        _iconImgV = [UIImageView ha_createImageView];
        _iconImgV.layer.cornerRadius = 22.5;
        _iconImgV.layer.masksToBounds = YES;
        _iconImgV.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(iconImgVClick)];
        [_iconImgV addGestureRecognizer:tap];
        _iconImgV.backgroundColor = [UIColor khaBGColor];
        [self.mainV addSubview:_iconImgV];
    }
    return _iconImgV;
}

- (UILabel *)nameL
{
    if (!_nameL) {
        _nameL = [UILabel ha_NLabelWithFont:16 textColor:@"#111A34" text:@"" alignment:0];
        [self.mainV addSubview:_nameL];
    }
    return _nameL;
}
- (UILabel *)mobileL
{
    if (!_mobileL) {
        _mobileL = [UILabel ha_NLabelWithFont:12 textColor:@"#858B9C" text:@"" alignment:0];
        [self.mainV addSubview:_mobileL];
    }
    return _mobileL;
}

- (UILabel *)timeL
{
    if (!_timeL) {
        _timeL = [UILabel ha_NLabelWithFont:12 textColor:@"#858B9C" text:@"" alignment:0];
        [self.mainV addSubview:_timeL];
    }
    return _timeL;
}

- (UIImageView *)rImgV
{
    if (!_rImgV) {
        _rImgV = [UIImageView ha_createImageView];
        _rImgV.image = [UIImage imageNamed:@"ic_cell_more"];
        [self.mainV addSubview:_rImgV];
    }
    return _rImgV;
}

- (UILabel *)yjL
{
    if (!_yjL) {
        _yjL = [UILabel ha_NLabelWithFont:16 textColor:@"#5F67FC" text:@"业绩" alignment:2];
        [self.mainV addSubview:_yjL];
    }
    return _yjL;
}

- (UIView *)lineV
{
    if (!_lineV) {
        _lineV = [UIView ha_createView];
        _lineV.backgroundColor = [UIColor kLineColor];
        [self.mainV addSubview:_lineV];
    }
    return _lineV;
}

- (UIButton *)bottomBtn1
{
    if (!_bottomBtn1) {
        _bottomBtn1 = [[UIButton alloc]init];
        [_bottomBtn1 setTitle:@"修改返现" forState:UIControlStateNormal];
        [_bottomBtn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _bottomBtn1.titleLabel.font = [UIFont systemFontOfSize:14];
        _bottomBtn1.backgroundColor = [UIColor colorWithHexString:@"#43E319"];
        _bottomBtn1.layer.cornerRadius = 4;
        _bottomBtn1.layer.masksToBounds = YES;
        [_bottomBtn1 addTarget:self action:@selector(bottomBtn1Click) forControlEvents:UIControlEventTouchUpInside];
        [self.mainV addSubview:_bottomBtn1];
    }
    return _bottomBtn1;
}

- (UIButton *)bottomBtn2
{
    if (!_bottomBtn2) {
        _bottomBtn2 = [[UIButton alloc]init];
        [_bottomBtn2 setTitle:@"修改分润" forState:UIControlStateNormal];
        [_bottomBtn2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _bottomBtn2.titleLabel.font = [UIFont systemFontOfSize:14];
        _bottomBtn2.backgroundColor = [UIColor colorWithHexString:@"#191919"];
        _bottomBtn2.layer.cornerRadius = 4;
        _bottomBtn2.layer.masksToBounds = YES;
        [_bottomBtn2 addTarget:self action:@selector(bottomBtn2Click) forControlEvents:UIControlEventTouchUpInside];
        [self.mainV addSubview:_bottomBtn2];
    }
    return _bottomBtn2;
}


@end
